package common;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import domain.PostBean;

public class Grash {

	public static List<PostBean> crashHtml(String url, String fid) throws IOException {
		// 发帖url：http://www.mala.cn/forum.php?mod=post&action=newthread&fid=7
		Document document = Jsoup.connect(url + "forum.php?mod=forumdisplay&fid=" + fid + "&orderby=dateline").get();
		Elements tidEles = document.select("[id^=normalthread]");
		List<PostBean> postList = new ArrayList<PostBean>();
		// 回帖url：forum.php?mod=post&action=reply&fid=7&tid=14520274
		for (Element element : tidEles) {
			PostBean postBean = new PostBean();
			String tidStr = element.attr("id");
			String tid = tidStr.substring(tidStr.indexOf("_") + 1);
			String postUrl = url + "forum.php?mod=post&action=reply&fid=" + fid + "&tid=" + tid;
			postBean.setUrl(postUrl);
			// 默认回复
			postBean.setMessage("我只能这个样了，顶一个先(来自：dydywang)");
			postList.add(postBean);
		}
		
		return postList;
	}
}
